import java.util.ArrayList;
/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
//4.2 没做出来 此题思想很赞
public class Solution {
    ArrayList<ArrayList<Integer>> result = new ArrayList<>();  //最终list
    ArrayList<Integer> path = new ArrayList<Integer>();  //路径list
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) {
        if(root == null){
            return result;
        }
        path.add(root.val);
        target -= root.val;
        //每一次需要重新new一个path，这样保证有多条路径
        if(target == 0 && root.left == null && root.right == null){
            result.add(new ArrayList<Integer>(path));
        }
        FindPath(root.left,target);
        FindPath(root.right,target);
        path.remove(path.size()-1);
        return result;
    }
}